﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace Store.Model.Models
{
    public partial class StoreContext : DbContext
    {
        public StoreContext()
        {
        }

        public StoreContext(DbContextOptions<StoreContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Addresse> Addresses { get; set; }
        public virtual DbSet<Commodity> Commodities { get; set; }
        public virtual DbSet<Employee> Employees { get; set; }
        public virtual DbSet<Menu> Menus { get; set; }
        public virtual DbSet<Order> Orders { get; set; }
        public virtual DbSet<Position> Positions { get; set; }
        public virtual DbSet<Promotion> Promotions { get; set; }
        public virtual DbSet<Property> Properties { get; set; }
        public virtual DbSet<Relation> Relations { get; set; }
        public virtual DbSet<RelationsCom> RelationsComs { get; set; }
        public virtual DbSet<Typee> Typees { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Data Source=GAOLEI\\SQLEXPRESS;Initial Catalog=Store;Integrated Security=True");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Addresse>(entity =>
            {
                entity.HasKey(e => e.AddressId)
                    .HasName("PK__Addresse__091C2AFB6023D699");

                entity.ToTable("Addresse");

                entity.Property(e => e.AddressName)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.AddressPostal)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Addresses)
                    .HasForeignKey(d => d.UserId)
                    .HasConstraintName("FK__Addresse__UserId__1CF15040");
            });

            modelBuilder.Entity<Commodity>(entity =>
            {
                entity.ToTable("Commodity");

                entity.Property(e => e.ArticleNumber)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Brand)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.CommodityContent)
                    .HasMaxLength(225)
                    .IsUnicode(false);

                entity.Property(e => e.CommodityImg)
                    .HasMaxLength(255)
                    .IsUnicode(false);

                entity.Property(e => e.CommodityName)
                    .HasMaxLength(100)
                    .IsUnicode(false);

                entity.Property(e => e.CommodityPrice).HasColumnType("decimal(9, 2)");

                entity.Property(e => e.CreatePeople)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.EalterPeople)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("EAlterPeople");

                entity.Property(e => e.EalterTime)
                    .HasColumnType("datetime")
                    .HasColumnName("EAlterTime");

                entity.Property(e => e.Payment)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Servicee)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Store)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Supplier)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.TjCommodity)
                    .HasMaxLength(40)
                    .IsUnicode(false);

                entity.Property(e => e.Url)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("URL");

                entity.HasOne(d => d.Promotion)
                    .WithMany(p => p.Commodities)
                    .HasForeignKey(d => d.PromotionId)
                    .HasConstraintName("FK__Commodity__Promo__24927208");

                entity.HasOne(d => d.Type)
                    .WithMany(p => p.Commodities)
                    .HasForeignKey(d => d.TypeId)
                    .HasConstraintName("FK__Commodity__TypeI__239E4DCF");
            });

            modelBuilder.Entity<Employee>(entity =>
            {
                entity.ToTable("Employee");

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.EalterPeople)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("EAlterPeople");

                entity.Property(e => e.EalterTime)
                    .HasColumnType("datetime")
                    .HasColumnName("EAlterTime");

                entity.Property(e => e.Email)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.EmployeeAccount)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.EmployeeName)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.EmployeePhone)
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.EntryTime).HasColumnType("datetime");

                entity.Property(e => e.Img)
                    .HasMaxLength(225)
                    .IsUnicode(false);

                entity.Property(e => e.PassWords)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.RegisterTime).HasColumnType("datetime");

                entity.Property(e => e.RemarkMessage)
                    .HasMaxLength(225)
                    .IsUnicode(false);

                entity.Property(e => e.Sex)
                    .HasMaxLength(10)
                    .IsUnicode(false);

                entity.HasOne(d => d.PidNavigation)
                    .WithMany(p => p.Employees)
                    .HasForeignKey(d => d.Pid)
                    .HasConstraintName("FK__Employee__Pid__1273C1CD");
            });

            modelBuilder.Entity<Menu>(entity =>
            {
                entity.HasKey(e => e.Mid)
                    .HasName("PK__Menu__C79638C250A73429");

                entity.ToTable("Menu");

                entity.Property(e => e.Mname)
                    .HasMaxLength(30)
                    .IsUnicode(false)
                    .HasColumnName("MName");

                entity.Property(e => e.Url)
                    .HasMaxLength(50)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Order>(entity =>
            {
                entity.Property(e => e.OrderCreateTime).HasColumnType("datetime");

                entity.Property(e => e.OrderNumber)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.OrderPrice).HasColumnType("decimal(9, 2)");

                entity.Property(e => e.OrderSource)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.HasOne(d => d.Commodity)
                    .WithMany(p => p.Orders)
                    .HasForeignKey(d => d.CommodityId)
                    .HasConstraintName("FK__Orders__Commodit__2E1BDC42");

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Orders)
                    .HasForeignKey(d => d.UserId)
                    .HasConstraintName("FK__Orders__UserId__2D27B809");
            });

            modelBuilder.Entity<Position>(entity =>
            {
                entity.HasKey(e => e.Pid)
                    .HasName("PK__Position__C5705938978C4B7D");

                entity.ToTable("Position");

                entity.Property(e => e.AlterPeople)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.AlterTime).HasColumnType("datetime");

                entity.Property(e => e.CreatePeople)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Describe)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Pcount).HasColumnName("PCount");

                entity.Property(e => e.PositionName)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Pstate).HasColumnName("PState");
            });

            modelBuilder.Entity<Promotion>(entity =>
            {
                entity.ToTable("Promotion");

                entity.Property(e => e.CreatePeople)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.PalterPeople)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("PAlterPeople");

                entity.Property(e => e.PalterTime)
                    .HasColumnType("datetime")
                    .HasColumnName("PAlterTime");

                entity.Property(e => e.Particulars)
                    .HasMaxLength(100)
                    .IsUnicode(false);

                entity.Property(e => e.PastdueTime).HasColumnType("datetime");

                entity.Property(e => e.Ptitle)
                    .HasMaxLength(50)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Property>(entity =>
            {
                entity.ToTable("Property");

                entity.Property(e => e.BarCade)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Color)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Size)
                    .HasMaxLength(30)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<Relation>(entity =>
            {
                entity.HasKey(e => e.Rid)
                    .HasName("PK__Relation__CAF055CA7748984A");

                entity.ToTable("Relation");

                entity.HasOne(d => d.MidNavigation)
                    .WithMany(p => p.Relations)
                    .HasForeignKey(d => d.Mid)
                    .HasConstraintName("FK__Relation__Mid__173876EA");

                entity.HasOne(d => d.PidNavigation)
                    .WithMany(p => p.Relations)
                    .HasForeignKey(d => d.Pid)
                    .HasConstraintName("FK__Relation__Pid__182C9B23");
            });

            modelBuilder.Entity<RelationsCom>(entity =>
            {
                entity.HasKey(e => e.Cid)
                    .HasName("PK__Relation__C1FFD861A9715F2D");

                entity.ToTable("RelationsCom");

                entity.HasOne(d => d.Commodity)
                    .WithMany(p => p.RelationsComs)
                    .HasForeignKey(d => d.CommodityId)
                    .HasConstraintName("FK__Relations__Commo__2A4B4B5E");

                entity.HasOne(d => d.Property)
                    .WithMany(p => p.RelationsComs)
                    .HasForeignKey(d => d.PropertyId)
                    .HasConstraintName("FK__Relations__Prope__29572725");
            });

            modelBuilder.Entity<Typee>(entity =>
            {
                entity.HasKey(e => e.TypeId)
                    .HasName("PK__Typee__516F03B54100811E");

                entity.ToTable("Typee");

                entity.Property(e => e.CreatePeople)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Describe)
                    .HasMaxLength(225)
                    .IsUnicode(false);

                entity.Property(e => e.EalterPeople)
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasColumnName("EAlterPeople");

                entity.Property(e => e.EalterTime)
                    .HasColumnType("datetime")
                    .HasColumnName("EAlterTime");

                entity.Property(e => e.Icon)
                    .HasMaxLength(225)
                    .IsUnicode(false);

                entity.Property(e => e.Ranks)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.TypeName)
                    .HasMaxLength(50)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.UserAccount)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.UserAvg).HasColumnType("decimal(9, 1)");

                entity.Property(e => e.UserBalance).HasColumnType("decimal(9, 2)");

                entity.Property(e => e.UserBirthday).HasColumnType("datetime");

                entity.Property(e => e.UserBuytime).HasColumnType("datetime");

                entity.Property(e => e.UserImg)
                    .HasMaxLength(255)
                    .IsUnicode(false);

                entity.Property(e => e.UserName)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.UserPhone)
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.UserPrice).HasColumnType("decimal(9, 1)");

                entity.Property(e => e.UserPwd)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.UserSex)
                    .HasMaxLength(10)
                    .IsUnicode(false);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
